import 'dart:io';
import 'package:flutter/services.dart';

class NativeVideoPlayerService {
  static const MethodChannel _channel = MethodChannel('native_video_player');
  
  /// 使用原生播放器播放视频
  static Future<String?> playVideo(String videoPath) async {
    try {
      if (!Platform.isMacOS) {
        throw PlatformException(
          code: 'UNSUPPORTED_PLATFORM',
          message: '原生播放器仅支持macOS',
        );
      }
      
      final String? windowId = await _channel.invokeMethod('playVideo', {
        'path': videoPath,
      });
      
      return windowId;
    } on PlatformException catch (e) {
      print('播放视频失败: ${e.message}');
      rethrow;
    } catch (e) {
      print('播放视频失败: $e');
      rethrow;
    }
  }
  
  /// 关闭播放器窗口
  static Future<bool> closePlayer(String windowId) async {
    try {
      final bool result = await _channel.invokeMethod('closePlayer', {
        'windowId': windowId,
      });
      
      return result;
    } on PlatformException catch (e) {
      print('关闭播放器失败: ${e.message}');
      return false;
    } catch (e) {
      print('关闭播放器失败: $e');
      return false;
    }
  }
}